//
//  XKUpdateTradePwdController.m
//  XKJF
//
//  Created by xyg on 2016/12/17.
//  Copyright © 2016年 xiaokang100. All rights reserved.
//

#import "XKUpdateTradePwdController.h"
#import "XKUpdateTradePwdView.h"
@interface XKUpdateTradePwdController ()<UITextFieldDelegate>

@property (nonatomic, strong) XKUpdateTradePwdView *updateTradePwdView;

@end

@implementation XKUpdateTradePwdController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [SVProgressHUD dismiss];
}

- (void)setupUI {
    self.navigationItem.title = @"修改交易密码";
    
    self.updateTradePwdView = [XKUpdateTradePwdView new];
    self.updateTradePwdView.frame = self.view.bounds;
    [self.view addSubview:self.updateTradePwdView];

    @weakify(self);
    self.updateTradePwdView.UpdateTradePwdBlock = ^(NSString *oldPwd, NSString *newPwdOne, NSString *newPwdTwo) {
        @strongify(self);
        [self updateTradePwdWithOldPwd:oldPwd newPwdOne:newPwdOne newPwdTwo:newPwdTwo];
    };
}


#pragma mark - 修改交易密码
- (void)updateTradePwdWithOldPwd:(NSString *)oldPwd newPwdOne:(NSString *)newPwdOne newPwdTwo:(NSString *)newPwdTwo {
    
    [self.view endEditing:YES];
    if (![newPwdOne isEqualToString:newPwdTwo]) {
        [SVProgressHUD showErrorWithStatus:@"新密码两次输入不一致!"];
        return;
    }
    [SVProgressHUD show];
    
    @weakify(self);
    [APIManager POSTRequestWith:APIPOSTRequestState_UpdateTradePassword parameters:@{@"pwd":newPwdTwo, @"oldpwd":oldPwd} successBlock:^(NSDictionary *successDict) {
        [SVProgressHUD showSuccessWithStatus:successDict[@"msg"]];
        // 延时返回
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            @strongify(self);
            [self.navigationController popViewControllerAnimated:YES];
        });
        [MobClick event:@"UpdateTradePwd"];// 友盟事件统计

    } failureBlock:^(NSDictionary *failureDict) {
        
    } errorBlock:^(NSError *error) {
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
